]> git.openstreetmap.org Git - rails.git/blobdiff - vendor/plugins/rails-i18n/tools/Rails I18n.tmbundle/Support/lib/yaml_waml.rb
First stage of i18n. Some migrations and extra plugins.
[rails.git] / vendor / plugins / rails-i18n / tools / Rails I18n.tmbundle / Support / lib / yaml_waml.rb
diff --git a/vendor/plugins/rails-i18n/tools/Rails I18n.tmbundle/Support/lib/yaml_waml.rb b/vendor/plugins/rails-i18n/tools/Rails I18n.tmbundle/Support/lib/yaml_waml.rb
new file mode 100644 (file)
index 0000000..a0dda2f
--- /dev/null
@@ -0,0 +1,37 @@
+# stolen from Kakutani Shintaro http://github.com/kakutani/yaml_waml
+
+require "yaml"
+
+class String
+  def is_binary_data?
+    false
+  end
+end
+
+module YamlWaml
+  def decode(orig_yamled)
+    yamled_str = case orig_yamled
+                 when String then orig_yamled
+                 when StringIO then orig_yamled.string
+                 else return orig_yamled
+                 end
+    yamled_str.gsub!(/\\x(\w{2})/){[$1].pack("H2")}
+    return yamled_str
+  end
+  module_function :decode
+end
+
+ObjectSpace.each_object(Class) do |klass|
+  klass.class_eval do
+    if method_defined?(:to_yaml) && !method_defined?(:to_yaml_with_decode)
+      def to_yaml_with_decode(*args)
+        io = args.shift if IO === args.first
+        yamled_str = YamlWaml.decode(to_yaml_without_decode(*args))
+        io.write(yamled_str) if io
+        return yamled_str
+      end
+      alias_method :to_yaml_without_decode, :to_yaml
+      alias_method :to_yaml, :to_yaml_with_decode
+    end
+  end
+end
\ No newline at end of file